﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OreSystem.Entities;
using OreSystem.DAL;
using OreSystem.Common;
namespace OreSystem.BLL {
    public class UserBLL {
        private UserDAL userDAL = new UserDAL();
        public User GetUserByUserName(string userName) {
            return userDAL.GetUserByUserName(userName);
        }
        public bool IsLogin(string name, string pw) {
            User user = userDAL.GetUserByUserName(name);
            if (user == null) {
                return false;
            }
            if (user.PassWord != GetMd5Pw(pw,name)){
                return false;
            }
            return true;
        }
        public string GetMd5Pw(string pw,string count) {
            return Encrypt.GetMD5(count.ToUpper() + pw + "OreSystem");
            
        }
        public IList<User> GetListByKeys(string keys) {
            return userDAL.GetUserByKeys(keys);
        }

        public void Save(User u){
            u.PassWord = GetMd5Pw(u.PassWord, u.UserName);
            userDAL.Save(u);
        }

        public User GetUserById(int id) {
            return userDAL.GetUserById(id);
        }

        public IList<User> GetAllList() {
            return userDAL.GetAllList();
        }

        public void Delete(User user) {
            userDAL.Delete(user);
            
        }     
       
    }
}
